//
//  API+Adm.swift
//  TTBLL-iOS
//
//  Created by Toj on 2/21/23.
//

import Foundation


STAPI.shared.requestAdm(api: .rewardAds)
STAPI.shared.requestAdm(api: .rewardAdsStrategy(id: 12345.to_string))
STAPI.shared.requestPayment(api: .prePayment)


protocol TTAPIRequestServiceProtocol {
    var value: String { get }
}

struct TTAPIRequest {
    var rawValue: String
    
    struct API {
        var rawValue: String
        
        struct Service {
            var rawValue: String
        }
    }
}

extension TTAPIRequest.API.Service {
    struct Adm { var rawValue: String }
    struct Payment { var rawValue: String }
}

extension TTAPIRequest.API.Service.Adm: TTAPIRequestServiceProtocol {
    var value: String { return rawValue }
    /// 
    static var rewardAds: TTAPIRequest.API.Service.Adm {
        return TTAPIRequest.API.Service.Adm(rawValue: "/adm/v1/negotiator/reward-ads")
    }
    
    static func rewardAdsStrategy(id: String) -> TTAPIRequest.API.Service.Adm {
        return TTAPIRequest.API.Service.Adm(rawValue: "/adm/v1/negotiator/reward-ads/\(id)")
    }
}

extension TTAPIRequest.API.Service.Payment: TTAPIRequestServiceProtocol {
    var value: String { return rawValue }
    /// 支付前置
    static var prePayment: TTAPIRequest.API.Service.Payment {
        return TTAPIRequest.API.Service.Payment(rawValue: "/payment/api/v2/get-pre-payment")
    }
}


class STAPI: NSObject {
    static let shared = STAPI()
    private override init() { }
    
    private func request(api url: TTAPIRequestServiceProtocol, parametters: [String: Any]? = nil) {
        print("-->toj: url: \(url.value)")
    }
    
    func requestAdm(api url: TTAPIRequest.API.Service.Adm, parametters: [String: Any]? = nil) {
        request(api: url, parametters: parametters)
    }
    
    func requestPayment(api url: TTAPIRequest.API.Service.Payment, parametters: [String: Any]? = nil) {
        request(api: url, parametters: parametters)
    }
}
